
var Global = require('Global');
cc.Class({
    extends: cc.Component,

    properties: {
        bg:{
            default:null,
            type:cc.Node,
        },
        gameText:{
            default:null,
            type:cc.Node,
        },
        scoreLabel:{
            default:null,
            type:cc.Label,
        },
        renewBtn:{
            default:null,
            type:cc.Button,
        },
        overEffect:cc.AudioClip,
        addCoin:cc.AudioClip,
        btnEffect:cc.AudioClip,
        score:0,
        changeScore:0,
    },        

    onEnable(){
        var action = cc.repeatForever(cc.sequence(cc.scaleTo(1,1.5),cc.scaleTo(1,1)));
        this.gameText.runAction(action);
        cc.audioEngine.playEffect(this.overEffect);
        this.score = Global.score;
        this.schedule(this.updateScore,0.1,cc.REPEAT_FOREVER,2);
        this.bg.on(cc.Node.EventType.TOUCH_START,function(event){
            cc.audioEngine.playEffect(this.addCoin);
            this.changeScore = this.score;
            this.scoreLabel.string = '最终得分：'+this.changeScore;
        },this);
        this.renewBtn.node.on(cc.Node.EventType.TOUCH_START,function(event){
            this.back();
        },this);
    },

    updateScore(){
        if(this.score <= this.changeScore){
            this.unschedule(this.updateScore);
        }
        this.changeScore += 20;
        this.changeScore = this.changeScore > this.score? this.score:this.changeScore;
        cc.audioEngine.playEffect(this.addCoin);
        this.scoreLabel.string = '最终得分:'+this.changeScore;
    },

    back(){
        Global.score = 0;
        Global.powerNum = 0;
        cc.audioEngine.playEffect(this.btnEffect);
        this.panelManager.setStartpanel(true);
        this.panelManager.setOverpanel(false);
    },

    start () {

    },

    // update (dt) {},
});
